package com.stn.zjx.givingtreasure.activity.userwallet;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.ActivityCompat;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.came.viewbguilib.ButtonBgUi;
import com.google.gson.Gson;
import com.lzy.okgo.callback.StringCallback;
import com.lzy.okgo.model.Response;
import com.stn.zjx.givingtreasure.R;
import com.stn.zjx.givingtreasure.base.BaseActivity;
import com.stn.zjx.givingtreasure.bean.UserTransferRecord;
import com.stn.zjx.givingtreasure.domain.UserTransferRecordSingleDomain;
import com.stn.zjx.givingtreasure.event.NetWorkEvent;
import com.stn.zjx.givingtreasure.net.BaseApi;
import com.stn.zjx.givingtreasure.net.impl.PayNetImpl;
import com.stn.zjx.givingtreasure.service.UserService;
import com.stn.zjx.givingtreasure.table.User;
import com.stn.zjx.givingtreasure.utils.ToolsUtils;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class UserTransferRecordDetailActivity extends BaseActivity {
    @BindView(R.id.back_bt)
    RelativeLayout backBt;
    @BindView(R.id.action_title)
    TextView actionTitle;
    @BindView(R.id.web_title)
    TextView webTitle;
    @BindView(R.id.action_add_bt)
    RelativeLayout actionAddBt;
    @BindView(R.id.action_refresh)
    RelativeLayout actionRefresh;
    @BindView(R.id.exit)
    RelativeLayout exit;
    @BindView(R.id.sure_bt)
    TextView sureBt;
    @BindView(R.id.skip_bt)
    TextView skipBt;
    @BindView(R.id.share_bt)
    RelativeLayout shareBt;
    @BindView(R.id.more_bt)
    RelativeLayout moreBt;
    @BindView(R.id.scan_bt)
    RelativeLayout scanBt;
    @BindView(R.id.release_bt)
    ButtonBgUi releaseBt;
    @BindView(R.id.search_iv)
    ImageView searchIv;
    @BindView(R.id.search_edit)
    EditText searchEdit;
    @BindView(R.id.search_bg)
    RelativeLayout searchBg;
    @BindView(R.id.save_bt)
    TextView saveBt;
    @BindView(R.id.flow_number)
    TextView flowNumber;
    @BindView(R.id.flow_number_tv)
    TextView flowNumberTv;
    @BindView(R.id.type)
    TextView type;
    @BindView(R.id.type_tv)
    TextView typeTv;
    @BindView(R.id.income)
    TextView income;
    @BindView(R.id.income_tv)
    TextView incomeTv;
    @BindView(R.id.payment_method)
    TextView paymentMethod;
    @BindView(R.id.payment_method_tv)
    TextView paymentMethodTv;
    @BindView(R.id.time)
    TextView time;
    @BindView(R.id.time_tv)
    TextView timeTv;
    @BindView(R.id.balance)
    TextView balance;
    @BindView(R.id.balance_tv)
    TextView balanceTv;
    @BindView(R.id.remarks)
    TextView remarks;
    @BindView(R.id.remarks_tv)
    TextView remarksTv;
      private UserTransferRecord data;
    @Override
    public void networkStatus(NetWorkEvent netWorkEvent) {

    }

    @SuppressLint("SetTextI18n")
    @Override
    public void initComponent() {
        data= (UserTransferRecord) getIntent().getSerializableExtra(    "data");
        actionTitle.setText(getString(R.string.income_expenditure_detail));
        flowNumber.setText(getString(R.string.flow_number)+":");
        type.setText(getString(R.string.type)+":");


        paymentMethod.setText(getString(R.string.payment_method)+":");
        time.setText(getString(R.string.time)+":");
        balance.setText(getString(R.string.balance)+":");
        remarks.setText(getString(R.string.remarks)+":");
        flowNumberTv.setText(data.getTransferFlowNumber());
        switch (data.getTransferRecordType()){
            case 0:
                typeTv.setText(getString(R.string.transfer));
                break;
            case 1:
                typeTv.setText(getString(R.string.withdraw));
                break;
            case 2:
                typeTv.setText(getString(R.string.recharge_to_balance));
                break;
        }
        switch (data.getTransferProfitType()){
            case 0:
                income.setText(getString(R.string.income)+":");
                incomeTv.setText("+"+data.getTransferMoney());
                incomeTv.setTextColor(ActivityCompat.getColor(this,R.color.default_green));
                break;
            case 1:
                income.setText(getString(R.string.expenditure)+":");
                incomeTv.setText("-"+data.getTransferMoney()+getString(R.string.rmb));
                incomeTv.setTextColor(ActivityCompat.getColor(this,R.color.default_red));
                break;
        }
        switch (data.getTrasnferPayType()){
            case 0:
                paymentMethodTv.setText(getString(R.string.balance));

                break;
            case 1:
                paymentMethodTv.setText(getString(R.string.alipay));
                break;
            case 2:
                paymentMethodTv.setText(getString(R.string.wechat));
                break;
            case 3:
                paymentMethodTv.setText(getString(R.string.quick_payment));
                break;
        }
        timeTv.setText(ToolsUtils.getDate(data.getTransferCreatedate(),"yyyy-MM-dd HH:mm:ss"));
        balanceTv.setText(String.valueOf(data.getTransferNowMoney()));
        remarksTv.setText(data.getTransferRemarks());
    }

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_user_transfer_record_detail);
        ButterKnife.bind(this);
        initComponent();
    }

    @OnClick({R.id.back_bt})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.back_bt:
                finish();
                break;

        }
    }

//    public void initRefresh(String token,String transferFlowNumber){
//        PayNetImpl
//                .query_user_transfer_record_by_flow_number(token, transferFlowNumber, transferFlowNumber + "_query_user_transfer_record_by_flow_number",
//                        new StringCallback() {
//                            @Override
//                            public void onSuccess(Response<String> response) {
//                                 if(response.isSuccessful()&&!isFinishing()){
//                                     init(response.body());
//                                 }
//                            }
//
//                            @Override
//                            public void onCacheSuccess(Response<String> response) {
//                                super.onCacheSuccess(response);
//                                if(response.isSuccessful()&&!isFinishing()){
//                                    init(response.body());
//                                }
//                            }
//                        });
//    }
//
//    public void init(String body){
//        UserTransferRecordSingleDomain domain=new Gson().fromJson(body,UserTransferRecordSingleDomain.class);
//         switch (domain.getStatus()){
//             case BaseApi.REQUEST_SUCCESS_CODE:
//
//                 break;
//         }
//    }
}
